package com.gjs.freechat.server.component.bean;

import java.util.concurrent.atomic.AtomicInteger;


public class UserInfo {
	public static int USER_STATUS_OFFLINE = 0;
	public static int USER_STATUS_ONLINE = 1;
	
	private String id;
	private String userName;
	private String email;
	private String nickName;
	private String avatarIcon;
	private String avatarIconName;
	private String avatarColor;
	private String introduction;
	private String interests;
	private String[] interestsArr;
	private int gender;             //1:男;2:女
	private int age;
	private String location;
	private String password;
	private int registered;    //0:没有注册，1：已经注册
	private int logined;  //0:没有登录，1:已登录
	//private AtomicInteger matchingNum = new AtomicInteger(0);
	
	public UserInfo () {}
	
	public UserInfo(String id, String userName, String nickName, 
			String avatarIcon, String avatarIconName, String avatarColor, int logined) {
		this.id = id;
		this.userName = userName;
		this.nickName = nickName;
		this.avatarColor = avatarColor;
		this.avatarIcon = avatarIcon;
		this.avatarIconName = avatarIconName;
		this.logined = logined;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getNickName() {
//		if (nickName == null || nickName.length() == 0) {
//			return avatarIconName;
//		}
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
	

	public String getAvatarIcon() {
		return avatarIcon;
	}

	public void setAvatarIcon(String avatarIcon) {
		this.avatarIcon = avatarIcon;
	}

	public String getAvatarIconName() {
		return avatarIconName;
	}

	public void setAvatarIconName(String avatarIconName) {
		this.avatarIconName = avatarIconName;
	}

	public String getAvatarColor() {
		return avatarColor;
	}

	public void setAvatarColor(String avatarColor) {
		this.avatarColor = avatarColor;
	}

	public String getIntroduction() {
		return introduction;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public String getInterests() {
		return interests;
	}

	public void setInterests(String interests) {
		this.interests = interests;
		if (interests != null && interests.length() != 0)
			interestsArr = interests.split(",");
	}

	public String[] getInterestsArr() {
		return interestsArr;
	}

	public void setInterestsArr(String[] interestsArr) {
		this.interestsArr = interestsArr;
	}

	

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
	
	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public int getRegistered() {
		return registered;
	}

	public void setRegistered(int registered) {
		this.registered = registered;
	}

	public int getLogined() {
		return logined;
	}

	public void setLogined(int logined) {
		this.logined = logined;
	}
	
	public String toString() {
		return "" + id + "," + userName + "," + nickName + "," + avatarColor + "," + avatarIcon;
	}
	
	public void updateBasicInfo(UserInfo userInfo) {
		if (id == null || id.length() == 0 || !id.equals(userInfo.getId()))
			return;
		age = userInfo.getAge();
		avatarColor = userInfo.getAvatarColor();
		avatarIcon = userInfo.getAvatarIcon();
		avatarIconName = userInfo.getAvatarIconName();
		gender = userInfo.getGender();
		setInterests(userInfo.getInterests());
		setIntroduction(userInfo.getIntroduction());
		location = userInfo.getLocation();
		nickName = userInfo.getNickName();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserInfo userInfo = (UserInfo) obj;
		if (id != null) {
			return id.equals(userInfo.getId());
		} else {
			return false;
		}
	}
}
